# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname=opensearch-sql-plugin
pkgver=2.6.0.0
pkgrel=1
_opensearchver=2.6.0
_jdkver=11
pkgdesc="OpenSearch SQL Plugin"
arch=('loong64' 'x86_64')
url="https://opensearch.org/docs/latest/search-plugins/sql"
license=('Apache')
depends=("opensearch=${_opensearchver}")
makedepends=("java-environment=${_jdkver}" 'unzip')
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/opensearch-project/sql/archive/${pkgver}.tar.gz"
)
sha256sums=('ab584a17a5ff40d7b659fd82367e5f410cca9b01dfa05b5f157528bc9588f4ef')

build() {
  cd "sql-${pkgver}"
  export JAVA_HOME="/usr/lib/jvm/java-${_jdkver}-openjdk"
  export PATH="/usr/lib/jvm/java-${_jdkver}-openjdk/bin:$PATH"
  export GRADLE_OPTS="-Dbuild.snapshot=false -Dopensearch.version=${_opensearchver}"
  # :doctest requires python 3.7
  # :sql:build and :integ-test (reaper) require JDK 14
  ./gradlew build \
    --exclude-task ":doctest:bootstrap" \
    --exclude-task ":doctest:stopOpenSearch" \
    --exclude-task ":doctest:doctest" \
    --exclude-task ":jacocoTestReport" \
    --exclude-task ":sql:build" \
    --exclude-task ":integ-test:integTest"
}

package() {
  install -dm755 "${pkgdir}/usr/share/opensearch/plugins/opensearch-sql"
  cd "${pkgdir}/usr/share/opensearch/plugins/opensearch-sql"
  unzip "${srcdir}/sql-${pkgver}/plugin/build/distributions/opensearch-sql-${pkgver}.zip"

  install -Dm644 "${srcdir}/sql-${pkgver}/LICENSE.txt" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"
}
